"""author: songzhiqiang
   data: 2021/11/21
   project: zuoye
"""
import random
with open("ips.txt",'w+') as f:
    for i in range(120):
        a = random.randint(0,255)
        ip = '172.25.254.' + str(a)
        f.writelines(ip)
        f.writelines('\n')
counts = {}
with open('ips.txt') as f:
    f.seek(0)
    for i in f:
        counts[i] = counts.get(i,0)+1
        # if i in counts:
        #     counts[i] += 1
        # else:
        #     counts[i] = 1

#{"172.25.254.1":5,"172.25.254.100":6,"172.25.254.200":3}
sort_list = counts.items()
sort = sorted(sort_list, key=lambda x: x[1], reverse=True)[:10]
print('出现频率前十的ip为：')
for i in sort:
    print(i[0],"出现次数：",i[1])
